package com.ruoyi.monitor.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.monitor.mapper.MonitorRetrievalRequestMapper;
import com.ruoyi.monitor.domain.MonitorRetrievalRequest;
import com.ruoyi.monitor.service.IMonitorRetrievalRequestService;

/**
 * 监控调取申请Service业务层处理
 * 
 * @author lh
 * @date 2025-04-16
 */
@Service
public class MonitorRetrievalRequestServiceImpl implements IMonitorRetrievalRequestService 
{
    @Autowired
    private MonitorRetrievalRequestMapper monitorRetrievalRequestMapper;

    /**
     * 查询监控调取申请
     * 
     * @param requestId 监控调取申请主键
     * @return 监控调取申请
     */
    @Override
    public MonitorRetrievalRequest selectMonitorRetrievalRequestByRequestId(Long requestId)
    {
        return monitorRetrievalRequestMapper.selectMonitorRetrievalRequestByRequestId(requestId);
    }

    /**
     * 查询监控调取申请列表
     * 
     * @param monitorRetrievalRequest 监控调取申请
     * @return 监控调取申请
     */
    @Override
    public List<MonitorRetrievalRequest> selectMonitorRetrievalRequestList(MonitorRetrievalRequest monitorRetrievalRequest)
    {
        return monitorRetrievalRequestMapper.selectMonitorRetrievalRequestList(monitorRetrievalRequest);
    }

    /**
     * 新增监控调取申请
     * 
     * @param monitorRetrievalRequest 监控调取申请
     * @return 结果
     */
    @Override
    public int insertMonitorRetrievalRequest(MonitorRetrievalRequest monitorRetrievalRequest)
    {
        monitorRetrievalRequest.setCreateTime(DateUtils.getNowDate());
        return monitorRetrievalRequestMapper.insertMonitorRetrievalRequest(monitorRetrievalRequest);
    }

    /**
     * 修改监控调取申请
     * 
     * @param monitorRetrievalRequest 监控调取申请
     * @return 结果
     */
    @Override
    public int updateMonitorRetrievalRequest(MonitorRetrievalRequest monitorRetrievalRequest)
    {
        return monitorRetrievalRequestMapper.updateMonitorRetrievalRequest(monitorRetrievalRequest);
    }

    /**
     * 批量删除监控调取申请
     * 
     * @param requestIds 需要删除的监控调取申请主键
     * @return 结果
     */
    @Override
    public int deleteMonitorRetrievalRequestByRequestIds(Long[] requestIds)
    {
        return monitorRetrievalRequestMapper.deleteMonitorRetrievalRequestByRequestIds(requestIds);
    }

    /**
     * 删除监控调取申请信息
     * 
     * @param requestId 监控调取申请主键
     * @return 结果
     */
    @Override
    public int deleteMonitorRetrievalRequestByRequestId(Long requestId)
    {
        return monitorRetrievalRequestMapper.deleteMonitorRetrievalRequestByRequestId(requestId);
    }

    /**
     * 查询指定用户的已批准申请
     *
     * @param userId 用户ID
     * @return 已批准的申请列表
     */
    @Override
    public List<MonitorRetrievalRequest> selectApprovedRequestsByUserId(Long userId)
    {
        // 创建查询条件对象
        MonitorRetrievalRequest query = new MonitorRetrievalRequest();
        query.setUserId(userId);
        query.setStatus("1"); // 1表示已批准
        
        // 执行查询并返回结果
        return monitorRetrievalRequestMapper.selectMonitorRetrievalRequestList(query);
    }
}
